<!DOCTYPE html>
<html>
<head>
    <title>我的游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userTravels.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog2/css/dialog.css"/>
    <script src="/js/plugins/dialog2/js/dialog.js"></script>

</head>
<script>
    $(function () {
        //当前登录用户
        var userJsonStr = sessionStorage.getItem('user');
        var user = JSON.parse(userJsonStr);

        //临时当前页
        var currentPage = 1;

        //总页数
        var totalPage = 1;

        //解决下一页时,上一页数据丢失的问题
        //使用临时变量保存所有List数据
        var dataList = [];

        //分页请求
        function query() {
            //发起请求获取我的游记的数据
            $.get("/users/" + user.id + "/travels", {currentPage: currentPage}, function (data) {
                //缓存分页数据
                var renderData = {
                    list: dataList
                }
                //
                dataList = $.merge(dataList, data.list);
                //将静态数据替换成动态数据
                $(".travels").renderValues(renderData, {
                    //表示数据渲染时, 调用render - fun 指定函数
                    //render -fun  render -key 配置使用的
                    //render -key, 表示function 中value参数
                    setHref: function (item, value) {
                        var href = $(item).data("href");
                        $(item).attr("href", href + value);
                        console.log(href);
                    }

                });
                //给下一次分页,currentPage + 1
                currentPage += 1;
                totalPage = data.pages;
            })
        }
        //第一分页
        //发起请求获取我的游记的数据
        query();
        //页面滑动监听
        $(window).scroll(function () {
            //判断是否进行分页
            if ($(document).scrollTop() + $(window).height() + 1 > $(document).height()) {
                //如果当前大于总页数,不需要再发出分页请求
                if (currentPage <= totalPage) {
                    query();
                } else {
                    $(document).dialog({
                        type: 'notice',
                        infoText: '已经到底了~',
                        autoClose: 1500,
                        position: 'bottom'
                    });
                }
            }
        })


    })
</script>
<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的游记</span>
        </div>
        <div class="col"></div>
    </div>
</div>


<div class="container travels">
    <dl class="list" render-loop="list">
        <dd>
            <a data-href="editTravels.html?id=" render-fun="setHref" render-key="list.id">
                <img render-src="list.coverUrl">
                <h6 class="title" render-html="list.title"> 骨灰级成都吃货地图</h6>
                <p>最近更新时间 <span render-html="list.lastUpdateTime">2018-07-13 12:46:27</span>
                    <span class="span-right">
                            <i class="fa fa-heart"></i><span>0</span>收藏
                            <i class="fa fa-thumbs-o-up"></i><span>0</span>点赞</span>
                </p>
            </a>
        </dd>
    </dl>
</div>

</body>
</html>
